<?php


namespace app\api\service;
use think\Cache;


class BaseService
{

    public function xcxAccessToken($appid,$appSecret)
    {
        $time = time();
        $xcxaccess_token = [];
        $xcxaccess_token = Cache::get('xcxaccess_token');
        if (!isset($xcxaccess_token['expirtime']) || $xcxaccess_token['expirtime']>$time) {
            $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appSecret;
            $data = http_request($url);
            if ($data && isset($data['access_token'])) {
                $xcxaccess_token['token'] = $data['access_token'];
                $xcxaccess_token['expirtime'] = $time+3600;
                Cache::set('xcxaccess_token',$xcxaccess_token,3600);
            }
        }
        return $xcxaccess_token['token'];
    }
}